package com.example.controller;

import com.example.compents.iec.iec104.common.BasicInstruction104;
import com.example.compents.iec.iec104.common.NettyChannelMng;
import com.example.compents.iec.iec104.enums.QualifiersEnum;
import io.netty.channel.Channel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.net.UnknownHostException;

@RestController
@RequestMapping("/iec")
public class Iec104Controller {



    @GetMapping("/sendStartFram")
    public void sendStartFram() throws UnknownHostException {
        String ip = InetAddress.getLocalHost().getHostAddress();
        Channel channel=NettyChannelMng.getActiveDeviceChannel(ip);
        channel.writeAndFlush(BasicInstruction104.STARTDT);
    }

    @GetMapping("/sendGeneralCall")
    public void sendGeneralCall() throws UnknownHostException {
        String ip = InetAddress.getLocalHost().getHostAddress();
        Channel channel=NettyChannelMng.getActiveDeviceChannel(ip);
        channel.writeAndFlush(BasicInstruction104.getGeneralCallRuleDetail104());
    }
    @GetMapping("/sendRemoteAdjustExecute")
    public void sendRemoteAdjustExecute() throws UnknownHostException {
        String ip = InetAddress.getLocalHost().getHostAddress();
        Channel channel=NettyChannelMng.getActiveDeviceChannel(ip);
        channel.writeAndFlush(QualifiersEnum.qualityQualifierRemoteAdjustExecute);
    }

    @GetMapping("/sendRemoteAdjustSelect")
    public void sendRemoteAdjustSelect() throws UnknownHostException {
        String ip = InetAddress.getLocalHost().getHostAddress();
        Channel channel=NettyChannelMng.getActiveDeviceChannel(ip);
        channel.writeAndFlush(QualifiersEnum.qualityQualifierRemoteAdjustSelect);
    }
    @GetMapping("/sendRemoteControl")
    public void sendRemoteControl() throws UnknownHostException {
        String ip = InetAddress.getLocalHost().getHostAddress();
        Channel channel=NettyChannelMng.getActiveDeviceChannel(ip);
        channel.writeAndFlush(BasicInstruction104.getRemoteControlRuleDetail104());
    }

}
